#ifndef TCP_SERVER_EVENTLOOPTHREAD_H
#define TCP_SERVER_EVENTLOOPTHREAD_H

#include "../../base/noncopyable.h"
#include "../../base/thread/Mutex.h"
#include "../../base/thread/Thread.h"

class EventLoop;

class EventLoopThread : muduo::noncopyable {
public:
    typedef std::function<void(EventLoop *)> ThreadInitCallback;

    explicit EventLoopThread(ThreadInitCallback cb = ThreadInitCallback(),
                             const string &name = string());

    ~EventLoopThread();

    EventLoop *startLoop();

private:
    void threadFunc();

    EventLoop *loop_;
    // 线程对应的事件循环
    bool exiting_;
    // 是否在退出中
    Thread thread_;
    MutexLock mutex_;
    Condition cond_;
    // 条件变量
    ThreadInitCallback callback_;
    // 线程初始化回调函数
};


#endif //TCP_SERVER_EVENTLOOPTHREAD_H
